import MySQLdb

class DataBase:
    def __init__(self):
        self.host = 'rm-2ze5v10naod3h1665no.mysql.rds.aliyuncs.com'
        self.port = 3306
        self.user = 'zevin'
        self.password = 'Aa123456'
        self.db = 'postgraduate_exam'
        self.charset = 'utf8'

    def get_config(self):
        config = {"host": self.host,
                  "port": self.port,
                  "user": self.user,
                  "passwd": self.password,
                  "db": self.db,
                  "charset": self.charset}

        return config

    def get_host(self):
        return self.host

    def get_port(self):
        return self.port

    def get_user(self):
        return self.user

    def get_password(self):
        return self.password

    def get_db(self):
        return self.db

    def get_charset(self):
        return self.charset

if __name__ == '__main__':
    config = DataBase().get_config()
    print("连接测试")
    try:
        conn = MySQLdb.connect(**config)
        print("连接成功")
    except Exception:
        print("连接出错")
